﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Admin/Admin.master" AutoEventWireup="true"
    CodeFile="usersSetting.aspx.cs" Inherits="Admin_usersSetting" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server">
    <script type="text/javascript">
        $(function () {
            darren.form({
                appendTo: $(".form2"),
                title: "添加管理员",
                data: {},
                width: 900,
                items: [
                { id: "Id", label: "Id", type: "hidden", required: true },
				{ id: "UserName", label: "用户名", type: "textbox", required: true },
				{ id: "Password", label: "密码", type: "textbox", required: true },				
                { id: "submit", label: "添加", type: "submit", iconCls: "icon-save", url: "",
                    onClick: function (isValid, formData) {
                        SixLottery.Models.Member.CreateMember(formData, { success: function (result) {
                            if (result.ErrorCode == 0) {
                                //alert("添加成功!");
                                $('#grid').datagrid("reload");
                            } else {
                                alert("添加失败：" + result.Description);
                            }
                        } 
                        });
                    },
                    success: function (isValid, data) {
                        success(data);
                    },
                    onLoadError: function () {
                    }
                }
                ]
            });

            function getData() {
                var setting = $('#grid').datagrid("options");
                var result = SixLottery.Models.Member.GetPaging(parseInt(setting.pageSize), setting.pageNumber);
                //console.log(result);
                if (result.ErrorCode == 0)
                    return result.Value;
                else
                    alert(result.Name);
            }

            var lastIndex;
            $('#grid').datagrid({
                title: '管理员列表',
                iconCls: 'icon-save',
                width: 900,
                height: 500,
                nowrap: false,
                striped: false,
                collapsible: false, //是否显示收放按钮
                pageSize: 10,
                pageList: [10, 20],
                datafun: getData,
                sortName: 'UserName', //初始排序字段
                sortOrder: 'desc',            //初始排序
                idField: 'UserName',
                queryParams: { pid: 1234 }, //附加参数
                showFooter: true,
                remoteSort: true, //通过服务端排序
                singleSelect: true,
                columns: [[
					{ field: "UserName", title: '用户名', width: 120 },
					{ field: "Password", title: '密码', editor: "text", width: 220, formatter: function (value, rowData, rowIndex) { return value.substr(0, 30); } },					
                    { field: "control", title: '操作', width: 150, formatter: function (value, rowData, rowIndex) {
                        return "<a href=\"javascript:admin.del('" + rowData.UserName + "')\">删除</a>"
                    }
                    }
				]],
                pagination: true,
                rownumbers: true,
                onDblClickRow: function (rowIndex) {
                    if (lastIndex != rowIndex) {
                        $('#grid').datagrid('endEdit', lastIndex);
                        $('#grid').datagrid('beginEdit', rowIndex);
                    }
                    lastIndex = rowIndex;
                },
                onClickRow: function (rowIndex) {
                    $('#grid').datagrid('endEdit', lastIndex);
                    lastIndex = -1;
                },
                onAfterEdit: function (rowIndex, rowData, changes) {
                    var c = $.extend({ Password: 0, Level: -1 }, changes);
                    if (c.Password == 0)
                        return;
                    SixLottery.Models.Member.Update(rowData);
                }
            });
        });

        var admin = {
            del: function (username) {
                if (confirm("确定要删除吗?")) {
                    SixLottery.Models.Member.Delete(username, { success: function () {
                        $('#grid').datagrid("reload");
                    } 
                    });
                }
            },
            edit: function (id) { parent.OpenTab({ title: "编辑:" + id, id: id, url: "edit.aspx?pid=" + id }); }
        };
    </script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
    <div class="form2">
    </div>
    <div id="grid">
    </div>
</asp:Content>
